﻿namespace AnyOffice.WebControls
{
    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    [ToolboxData("<{0}:HFDataList runat=server></{0}:HFDataList>"), DefaultProperty("Text")]
    public class HFDataList : DataList
    {
        private string strBigIco = "";
        private string strHoverBigIco = "";
        private _ShowModel strShowMode;
        private string strSmallIco = "";
        private string strUrl = "";
        private string strUrlName = "";

        public void AddCols(string[] cols)
        {
            this.ItemTemplate = new AnyOffice.WebControls.DataListItemTemplate(cols, this.strSmallIco, this.strUrl);
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (this.strShowMode == _ShowModel.BigIcon)
            {
                this.Width = Unit.Percentage(100.0);
                this.ItemTemplate = new DataListBigIcoTemplate(this.strBigIco, this.strUrl, this.strUrlName);
            }
        }

        [Bindable(true), Description("对应的大图标"), Category("HFServer"), Browsable(true)]
        public string BigIcoUrl
        {
            get
            {
                if (base.Attributes["BigIcoUrl"] != null)
                {
                    this.strBigIco = base.Attributes["BigIcoUrl"].Trim();
                }
                return this.strBigIco;
            }
            set
            {
                this.strBigIco = value;
                base.Attributes.Add("BigIcoUrl", this.strBigIco);
            }
        }

        [Category("HFServer"), Browsable(true), Description("对应的链接大图标"), Bindable(true)]
        public string HoverBigIco
        {
            get
            {
                if (base.Attributes["HoverBigIco"] != null)
                {
                    this.strHoverBigIco = base.Attributes["HoverBigIco"].Trim();
                }
                return this.strHoverBigIco;
            }
            set
            {
                this.strHoverBigIco = value;
                base.Attributes.Add("HoverBigIco", this.strHoverBigIco);
            }
        }

        [Bindable(true), Category("HFServer"), DefaultValue("BigIcon"), Description("显示方式"), Browsable(true)]
        public _ShowModel ShowMode
        {
            get
            {
                return this.strShowMode;
            }
            set
            {
                this.strShowMode = value;
                base.Attributes.Add("ShowMode", this.strShowMode.ToString());
            }
        }

        [Bindable(true), Browsable(true), Description("对应的小图标"), Category("HFServer")]
        public string SmallIcoUrl
        {
            get
            {
                if (base.Attributes["SmallIcoUrl"] != null)
                {
                    this.strSmallIco = base.Attributes["SmallIcoUrl"].Trim();
                }
                return this.strSmallIco;
            }
            set
            {
                this.strSmallIco = value;
                base.Attributes.Add("SmallIcoUrl", this.strSmallIco);
            }
        }

        [Description("每个图标对应的链接地址字段"), Browsable(true), Bindable(true), Category("HFServer")]
        public string Url
        {
            get
            {
                if (base.Attributes["Url"] != null)
                {
                    this.strUrl = base.Attributes["Url"].Trim();
                }
                return this.strUrl;
            }
            set
            {
                this.strUrl = value;
                base.Attributes.Add("Url", this.strUrl);
            }
        }

        [Category("HFServer"), Description("每个图标对应的链接地址字段"), Bindable(true), Browsable(true)]
        public string UrlName
        {
            get
            {
                if (base.Attributes["UrlName"] != null)
                {
                    this.strUrlName = base.Attributes["UrlName"].Trim();
                }
                return this.strUrlName;
            }
            set
            {
                this.strUrlName = value;
                base.Attributes.Add("UrlName", this.strUrlName);
            }
        }

        public enum _ShowModel
        {
            List,
            BigIcon
        }
    }
}

